package com.heima.model.search.dtos;

import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Date;

/**
 * @author Xiao
 * @version 1.0
 * @description
 * @date 2021/11/26
 */
@Data
public class UserSearchDto {
    private String searchWords; //搜索关键字
    private Integer pageNum;    //当前页
    private Integer pageSize;   //分页条数
    private Date minBehotTime;  //最小时间

    public int getFromIndex() {
        if (this.pageNum < 1) return 0;
        if (this.pageSize < 1) this.pageSize = 10;
        return this.pageSize * (pageNum - 1);
    }

    public void checkPage() {
        if (ObjectUtil.isEmpty(pageNum)) {
            this.setPageNum(1);
        }
        if (ObjectUtil.isEmpty(pageSize)) {
            this.setPageSize(20);
        }
        this.setPageSize(Math.min(20, pageSize));
    }
}
